<?php

class Colority extends DirModel
{
	
	public $viewModel=array(
		'ut_s_color',
		'ut_s_black',
		'ut_bs_color',
		'ut_bs_black'
	);
	
	public function getColorsCount()
	{
		return $this->ut_s_color+$this->ut_s_black+$this->ut_bs_color+$this->ut_bs_black;
	}

	public function getBlackCount()
	{
		return $this->ut_s_black+$this->ut_bs_black;
	}
	
	public function getColorityName($base=false)
	{
		return $this->ut_colority_name;
	}
	
	public function getSColors()
	{
		return $this->ut_s_color+$this->ut_s_black;
	}

	public function getBSColors()
	{
		return $this->ut_bs_color+$this->ut_bs_black;
	}	

	public function getColorGroup()
	{
		return $this->getSColors().'+'.$this->getBSColors();
	}		
	
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ut_colority';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ut_colority_name', 'required'),
			array('ut_colority_name', 'length', 'max'=>255),
		);
	}

	public function scopes()
	{
		return array(
			'base'=>array(
				'condition'=>'ut_colority_base=:base',
			),
			'absence'=>array(
				'condition'=>'NOT EXISTS (select * from ut_press_colority upc WHERE t.ut_colority_id=upc.ut_colority_id AND upc.ut_press_id=:press)',
			),
		);
	}	
	
	public function defaultScope()
	{
		return array('order'=>'ut_s_color+ut_s_black, ut_bs_color+ut_bs_black');
	}
	
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'colorityText'=>array(self::STAT,'PressPaper','ut_colority_id', 'select'=>'GROUP_CONCAT(ut_colority_id)'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'ut_colority_name' => 'Цветность',
		);
	}

}